package zara

class Task {
    String name
    Boolean available = false
    Integer seek =0

    
    Website website;
    User person

    static hasMany = [actions: WebAction]
    static belongsTo = Website

    static constraints = {
        name(size:1..50,blank:false ) 
        website();
        actions(nullable: true)
        seek()
        person()
    }

    static mapping = {
        actions sort  : "sortid"
       
    }
    String toString(){
        "${name}"
    }
    String buildAction(){
        def result =''
        if (actions) {
            actions.each{
                result += "${it.name} , ${it.target}${it.value?' , '+it.value:''}\r\n"
            }
        } 
        return result
    }

    String buildToJSON(){
        def result =''
        if (actions) {
            actions.each{
                result += "${it.name} , ${it.target}${it.value?' , '+it.value:''}||"
            }
        } 
        return result
    }
}
